//kte
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int N = 4e5 + 10;
int n;

ll read(){
	ll x = 0;
	char ch = getchar();
	while(ch < '0' || ch > '9'){
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9'){
		x = x * 10 + ch - '0';
		ch = getchar();
	}
	return x;
}

namespace solve1{
	ll st[N];
	int tp;
	map<ll, int> mp;
	int main(){
		for(int i = 1; i <= n; ++ i){
			ll a;
			scanf("%lld", &a);
			bool flg = 0;
			for(int j = 1; j <= tp; ++ j){
				if(st[j] == a){
					for(int k = j; k < tp; ++ k){
						st[k] = st[k+1];
					}
					flg = 1;
				}
			}
			if(flg){
				-- tp;
			} else {
				st[++tp] = a;
				sort(st + 1, st + tp + 1);
			}
			ll ans = 0, tmp = -st[1];
			for(int i = 1; i <= tp; ++ i){
				ans -= st[i] * (tp-i+1);
				ans += st[tp-i+1] * (tp-i+1);
				if(i < tp){
					tmp += st[tp-i+1] - st[i+1];
					ans -= max(tmp, 0ll);
				}
			}
			printf("%lld\n", ans);
		}
		return 0;
	}
}

namespace solve2{
	typedef unsigned long long ull;
	unordered_map<ll, int> mp;
	struct node{
		int pri, siz, ls, rs;
		ll val, sum;
		ull lv, rv;
	} t[N];
	ull gv;
	int tot = 1, rt, X, Y, Z;
	void upd(int p){
		t[p].siz = t[t[p].ls].siz + t[t[p].rs].siz + 1;
		t[p].lv = t[t[p].rs].lv + t[t[p].ls].lv + (t[t[p].ls].sum + t[p].val) * (t[t[p].rs].siz + 1);
		t[p].rv = t[t[p].ls].rv + t[t[p].rs].rv + (t[p].val + t[t[p].rs].sum) * (t[t[p].ls].siz + 1);
		t[p].sum = t[t[p].ls].sum + t[p].val + t[t[p].rs].sum; 
	}
	int nnd(ll v){
		++ tot;
		t[tot].pri = rand();
		t[tot].siz = 1;
		t[tot].val = t[tot].sum = t[tot].lv = t[tot].rv = v;
		return tot;
	}
	int mg(int x, int y){
		if(!x || !y){
			return x + y;
		}
		if(t[x].pri < t[y].pri){
			t[x].rs = mg(t[x].rs, y);
			upd(x);
			return x;
		} else {
			t[y].ls = mg(x, t[y].ls);
			upd(y);
			return y;
		}
	}
	void sp(int p, ll k, int &x, int &y){
		if(!p){
			x = y = 0;
			return;
		}
		if(t[p].val <= k){
			x = p;
			sp(t[p].rs, k, t[p].rs, y);
		} else {
			y = p;
			sp(t[p].ls, k, x, t[p].ls);
		}
		upd(p);
	}
	void spsiz(int p, int k, int &x, int &y){
		if(!p){
			x = y = 0;
			return;
		}
		if(t[t[p].ls].siz + 1 <= k){
			x = p;
			spsiz(t[p].rs, k - 1 - t[t[p].ls].siz, t[p].rs, y);
		} else {
			y = p;
			spsiz(t[p].ls, k, x, t[p].ls);
		}
		upd(p);
	}
	void ins(ll x){
		sp(rt, x, X, Y);
		rt = mg(mg(X, nnd(x)), Y);
	}
	void del(ll x){
		sp(rt, x, X, Y);
		sp(X, x-1, X, Z);
		rt = mg(X, Y);
	}
	ll get1(){
		int p = rt;
		while(t[p].ls){
			p = t[p].ls;
		}
		return t[p].val;
	}
	ll getR(int x){
		ll ans = 0;
		int p = rt;
		while(x){
			if(t[t[p].rs].siz >= x){
				p = t[p].rs;
			} else if(t[t[p].rs].siz + 1 == x){
				ans += t[t[p].rs].sum + t[p].val;
				break;
			} else {
				ans += t[t[p].rs].sum + t[p].val;
				x -= t[t[p].rs].siz + 1;
				p = t[p].ls;
			}
		}
		return ans;
	}
	ll getL(int x){
		ll ans = 0;
		int p = rt;
		while(x){
			if(t[t[p].ls].siz >= x){
				p = t[p].ls;
			} else if(t[t[p].ls].siz + 1 == x){
				ans += t[t[p].ls].sum + t[p].val;
				break;
			} else {
				ans += t[t[p].ls].sum + t[p].val;
				x -= t[t[p].ls].siz + 1;
				p = t[p].rs;
			}
		}
		return ans;
	}
	ll getC(int x){
		return getR(x) - getL(x+1);
	}
	ull getqzC(int x){
		spsiz(rt, x+1, X, Y);
		ull ans = -t[X].lv + gv;
		rt = mg(X, Y);
		spsiz(rt, t[rt].siz-x, X, Y);
		ans += t[Y].rv;
		rt = mg(X, Y);
		return ans;
	}
	ll getC(int l, int r){
		if(l > r){
			return 0;
		}
		if(l == 1){
			return getqzC(r);
		}
		return getqzC(r) - getqzC(l-1);
	}
	ull ans[N];
	ll xx[N];
	
	int main(){
		bool ded = 0;
		int ls = 1e9;
		for(int i = 1; i <= n; ++ i){
			ll x = read();
			xx[i] = x;
			bool flg = 0;
			if(mp[x]){
				mp[x] = 0;
				del(x);
				ded = 1;
			} else {
				mp[x] = 1;
				ins(x);
				flg = 1;
			}
			if(xx[i] == xx[i-1]){
				ans[i] = ans[i-2];
				printf("%llu\n", ans[i]);
				ls = 1e9;
			} else {
				ull tmp = t[rt].rv - t[rt].lv;
				gv = get1();
				int L = 1, R = t[rt].siz / 2 + 1;
				if(flg == 1){
					R = min(R, ls + 1);
				}
				if(ded == 0){
					L = R;
					while(L-1 >= 1 && getC(L-1) >= 0) -- L;
				}
				if(getC(L) >= 0) R = L;
				while(L < R){
					int mid = L + R >> 1;
					if(getC(mid) >= 0){
						R = mid;
					} else {
						L = mid + 1;
					}
				}
				// printf("[%d]", L);
				ls = L;
				tmp -= getC(L, t[rt].siz - 1 - L);
				printf("%llu\n", tmp);
				ans[i] = tmp;
			}
		}
		return 0;
	}
}

int main(){
	freopen("kte.in", "r", stdin);
	freopen("kte.out", "w", stdout);
	scanf("%d", &n);
	if(n <= 1000){
		solve1::main();
	} else {
		solve2::main();
	}
	return 0;
}